<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!-- 新增/Add -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/diy.css">
    <script src="../../js/axios.min.js"></script>

    <style>
        img {
            width: 200px;
        }


    </style>
</head>

<body>
<article class="sign_in">
    <div class="warp tpl">
        <div class="layui-container">
            <div class="layui-row">
                <form class="layui-form" action="">
                    <div class="from-input-box-i">
                        <div class="layui-form-item unique" id="route_name_box">
                            <label class="layui-form-label">路线名称</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入路线名称"
                                       class="layui-input" id="route_name">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="route_number_box">
                            <label class="layui-form-label">路线编号</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入路线编号"
                                       class="layui-input" id="route_number">
                            </div>
                        </div>
                        <div class="layui-upload " id="cover_photo_box">
                            <button type="button" class="layui-btn" id="cover_photo">上传图片</button>
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" id="cover_photo_img">
                                <p id="demoText"></p>
                            </div>
                            <div style="width: 95px;">
                                <div class="layui-progress layui-progress-big" lay-showpercent="yes"
                                     lay-filter="cover_photo">
                                    <div class="layui-progress-bar" lay-percent=""></div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="starting_point_of_the_route_box">
                            <label class="layui-form-label">路线起点</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入路线起点"
                                       class="layui-input" id="starting_point_of_the_route">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="route_endpoint_box">
                            <label class="layui-form-label">路线终点</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入路线终点"
                                       class="layui-input" id="route_endpoint">
                            </div>
                        </div>

                        <div class="layui-form-item unique" id="team_opening_time_box">
                            <label class="layui-form-label">开团时间</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请选择开团时间"
                                       class="layui-input" id="team_opening_time">
                            </div>
                        </div>

                        <div class="layui-form-item number" id="number_of_group_members_box">
                            <label class="layui-form-label">组团人数</label>
                            <div class="layui-input-block input-i block">
                                <input type="number" name="num" class="layui-input num" id="number_of_group_members">
                            </div>
                        </div>
                        <div class="layui-form-item number" id="individual_expenses_box">
                            <label class="layui-form-label">单人费用</label>
                            <div class="layui-input-block input-i block">
                                <input type="number" name="num" class="layui-input num" id="individual_expenses">
                            </div>
                        </div>
                        <div class="layui-form-item select-box" id="tourism_classification_box">
                            <label class="layui-form-label">旅游分类</label>
                            <div class="layui-input-block select block">
                                <select name="interest" lay-filter="tourism_classification" id="tourism_classification">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item select-box" id="guide_name_box" style="display: none;">
                            <label class="layui-form-label">导游</label>
                            <div class="layui-input-block select block">
                                <select name="interest" lay-filter="guide_name" id="guide_name">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item select-box" id="driver_name_box" style="display: none;">
                            <label class="layui-form-label">司机</label>
                            <div class="layui-input-block select block">
                                <select name="interest" lay-filter="driver_name" id="driver_name">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text" id="tour_guide_information_box">
                            <label class="layui-form-label">导游信息</label>
                            <div class="layui-input-block text">
                                            <textarea placeholder="请输入导游信息" class="layui-textarea"
                                                      id="tour_guide_information"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item edit">
                            <label class="layui-form-label">路线详情</label>
                            <div class="layui-input-block text">
                                <textarea id="route_details" style="display: none;"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item edit">
                            <label class="layui-form-label">预订须知</label>
                            <div class="layui-input-block text">
                                <textarea id="booking_notice" style="display: none;"></textarea>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="layui-btn-container">
                    <button type="button" class="layui-btn layui-btn-normal login" id="submit">确认</button>
                    <button type="button" class="layui-btn layui-btn-normal login" id="cancel">取消</button>
                </div>
            </div>
        </div>
    </div>
</article>
</body>
<script src="../../layui/layui.js"></script>
<script src="../../js/base.js"></script>
<script src="../../js/index.js"></script>

<script>
    var BaseUrl = baseUrl()
    let cancel = document.querySelector("#cancel")
    cancel.addEventListener("click", () => {
        colseLayer()
    })
    let tourist_routes_id = location.search.substring(1)
    layui.use(['upload', 'element', 'layer', 'laydate', 'layedit'], function () {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer
            , laydate = layui.laydate
            , layedit = layui.layedit
            , form = layui.form;

        let url

        let token = sessionStorage.token || null
        let personInfo = JSON.parse(sessionStorage.personInfo)
        let user_group = personInfo.user_group
        let use_id = personInfo.user_id


        function $get_stamp() {
            return new Date().getTime();
        }

        function $get_rand(len) {
            var rand = Math.random();
            return Math.ceil(rand * 10 ** len);
        }


        // 权限判断
        /**
         * 获取路径对应操作权限 鉴权
         * @param {String} action 操作名
         */
        function $check_action(path1, action = "get") {
            var o = $get_power(path1);
            if (o && o[action] != 0 && o[action] != false) {
                return true;
            }
            return false;
        }

        /**
         * 是否有显示或操作字段的权限
         * @param {String} action 操作名
         * @param {String} field 查询的字段
         */
        function $check_field(action, field, path1) {
            var o = $get_power(path1);
            var auth;
            if (o && o[action] != 0 && o[action] != false) {
                auth = o["field_" + action];
            }
            if (auth) {
                return auth.indexOf(field) !== -1;
            }
            return false;
        }

        /**
         * 获取权限
         * @param {String} path 路由路径
         */
        function $get_power(path) {
            var list_data = JSON.parse(sessionStorage.list_data)
            var list = list_data;
            var obj;
            for (var i = 0; i < list.length; i++) {
                var o = list[i];
                if (o.path === path) {
                    obj = o;
                    break;
                }
            }
            return obj;
        }

        let submit = document.querySelector('#submit')
        // 提交按钮校验权限
        if (user_group == "管理员" || $check_action('/tourist_routes/view', 'add') || $check_action('/tourist_routes/view', 'set') || $check_option('/tourist_routes/table', 'examine')) {
        } else {
            $("#submit").hide()
        }
        // style="display: none"


        let field = "tourist_routes_id";
        let url_add = "tourist_routes";
        let url_set = "tourist_routes";
        let url_get_obj = "tourist_routes";
        let url_upload = "tourist_routes"
        let query = {
            "tourist_routes_id": 0,
        }

        let form_data2 = {
            "route_name": '', // 路线名称
            "route_number": $get_stamp(), // 路线编号
            "cover_photo": '', // 封面图片
            "starting_point_of_the_route": '', // 路线起点
            "route_endpoint": '', // 路线终点
            "team_opening_time": '', // 开团时间
            "number_of_group_members": 0, // 组团人数
            "individual_expenses": 0, // 单人费用
            "tourism_classification": '', // 旅游分类
            "tour_guide_information": '', // 导游信息
            "guide_name": '', // 导游
            "driver_name": '', // 司机
            "route_details": '', // 路线详情
            "booking_notice": '', // 预订须知
            "tourist_routes_id": 0, // ID
        }

        layui.layedit.set({
            uploadImage: {
                url: BaseUrl + '/api/tourist_routes/upload?' //接口url
                , type: 'post' //默认post
            }
        });


        var path1

        function getpath() {
            var list_data = JSON.parse(sessionStorage.list_data)
            for (var i = 0; i < list_data.length; i++) {
                var o = list_data[i];
                if (o.path === "/tourist_routes/table") {
                    path1 = o.path
                    $get_power(o.path)
                }
            }
        }

        getpath()

        /**
         * 注册时是否有显示或操作字段的权限
         * @param {String} action 操作名
         * @param {String} field 查询的字段
         * @param {String} path 路径
         */
        function $check_register_field(action, field, path1) {
            var o = $get_power(path1);
            var auth;
            if (o && o[action] != 0 && o[action] != false) {
                auth = o["field_" + action];
            }
            if (auth) {
                return auth.indexOf(field) !== -1;
            }
            return false;
        }

        /**
         * 是否有显示或操作字段的权限
         * @param {String} action 操作名
         * @param {String} field 查询的字段
         */
        function $check_field(action, field) {
            var o = $get_power("/tourist_routes/view");
            var auth;
            if (o && o[action] != 0 && o[action] != false) {
                auth = o["field_" + action];
            }
            if (auth) {
                return auth.indexOf(field) !== -1;
            }
            return false;
        }

        /**
         * 获取路径对应操作权限 鉴权
         * @param {String} action 操作名
         */
        function $check_exam(path1, action = "get") {
            var o = $get_power(path1);
            if (o) {
                var option = JSON.parse(o.option);
                if (option[action])
                    return true
            }
            return false;
        }

        function $check_option(path, op) {
            var o = $get_power(path);
            if (o) {
                var option = JSON.parse(o.option);
                if (option[op])
                    return true
            }
            return false;
        }

        /**
         * 是否有审核字段的权限
         */
        function $check_examine() {
            var url = window.location.href;
            var url_ = url.split("/")
            var pg_url = url_[url_.length - 2]
            let path = "/" + pg_url + "/table"
            var o = $get_power(path);
            if (o) {
                var option = JSON.parse(o.option);
                if (option.examine)
                    return true
            }
            return false;
        }

        function $show_guide_name_driver_name() {
            if (form_data2.tourism_classification === '周边游') {
                $("#guide_name_box").show()
                $("#driver_name_box").show()
            } else {
                $("#guide_name_box").hide()
                $("#driver_name_box").hide()
            }
        }

        if (user_group === '管理员') {
            $("#route_name_box").show()
        } else {
            if ($check_field('add', 'route_name')) {
                $("#route_name_box").show()
            } else {
                $("#route_name_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#route_number_box").show()
        } else {
            if ($check_field('add', 'route_number')) {
                $("#route_number_box").show()
            } else {
                $("#route_number_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#cover_photo_box").show()
        } else {
            if ($check_field('add', 'cover_photo')) {
                $("#cover_photo_box").show()
            } else {
                $("#cover_photo_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#starting_point_of_the_route_box").show()
        } else {
            if ($check_field('add', 'starting_point_of_the_route')) {
                $("#starting_point_of_the_route_box").show()
            } else {
                $("#starting_point_of_the_route_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#route_endpoint_box").show()
        } else {
            if ($check_field('add', 'route_endpoint')) {
                $("#route_endpoint_box").show()
            } else {
                $("#route_endpoint_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#team_opening_time_box").show()
        } else {
            if ($check_field('add', 'team_opening_time')) {
                $("#team_opening_time_box").show()
            } else {
                $("#team_opening_time_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#number_of_group_members_box").show()
        } else {
            if ($check_field('add', 'number_of_group_members')) {
                $("#number_of_group_members_box").show()
            } else {
                $("#number_of_group_members_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#individual_expenses_box").show()
        } else {
            if ($check_field('add', 'individual_expenses')) {
                $("#individual_expenses_box").show()
            } else {
                $("#individual_expenses_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#tourism_classification_box").show()
        } else {
            if ($check_field('add', 'tourism_classification')) {
                $("#tourism_classification_box").show()
            } else {
                $("#tourism_classification_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#tour_guide_information_box").show()
        } else {
            if ($check_field('add', 'tour_guide_information')) {
                $("#tour_guide_information_box").show()
            } else {
                $("#tour_guide_information_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#guide_name_box").show()
        } else {
            if ($check_field('add', 'guide_name')) {
                $("#guide_name_box").show()
            } else {
                $("#guide_name_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#driver_name_box").show()
        } else {
            if ($check_field('add', 'driver_name')) {
                $("#driver_name_box").show()
            } else {
                $("#driver_name_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#route_details_box").show()
        } else {
            if ($check_field('add', 'route_details')) {
                $("#route_details_box").show()
            } else {
                $("#route_details_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#booking_notice_box").show()
        } else {
            if ($check_field('add', 'booking_notice')) {
                $("#booking_notice_box").show()
            } else {
                $("#booking_notice_box").hide()
            }
        }

        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '#cover_photo'
            , url: BaseUrl + '/api/tourist_routes/upload?' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            , headers: {
                'x-auth-token': token
            }, before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#cover_photo_img').attr('src', fullUrl(BaseUrl, result)); //图片链接（base64）
                });

                element.progress('cover_photo', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功的一些操作
                //……
                form_data2.cover_photo = res.result.url
                $('#demoText').html(''); //置空上传失败的状态
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
            //进度条
            , progress: function (n, elem, e) {
                element.progress('cover_photo', n + '%'); //可配合 layui 进度条元素使用
                if (n == 100) {
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });
        var route_details = layedit.build('route_details', {
            tool: [
                'strong' //加粗
                , 'italic' //斜体
                , 'underline' //下划线
                , 'del' //删除/Del线
                , '|' //分割线
                , 'left' //左对齐
                , 'center' //居中对齐
                , 'right' //右对齐
                , 'link' //超链接
                , 'unlink' //清除链接
                , 'image' //插入图片
                , 'help' //帮助
            ]
        });
        var booking_notice = layedit.build('booking_notice', {
            tool: [
                'strong' //加粗
                , 'italic' //斜体
                , 'underline' //下划线
                , 'del' //删除/Del线
                , '|' //分割线
                , 'left' //左对齐
                , 'center' //居中对齐
                , 'right' //右对齐
                , 'link' //超链接
                , 'unlink' //清除链接
                , 'image' //插入图片
                , 'help' //帮助
            ]
        });

        laydate.render({
            elem: '#team_opening_time'
            , type: 'datetime'
            , done: function (value) {
                console.log(value)
                form_data2.team_opening_time = value
            }
        });

        async function tourism_classification() {
            var tourism_classification = document.querySelector("#tourism_classification")
            var op1 = document.createElement("option");
            op1.value = '0'
            tourism_classification.appendChild(op1)
            // 收集数据 长度
            var count
            // 收集数据 数组
            var arr = []
            let {data: res} = await axios.get(BaseUrl + '/api/tourism_classification/get_list')
            count = res.result.count
            arr = res.result.list
            for (var i = 0; i < arr.length; i++) {
                var op = document.createElement("option");

                // 给节点赋值
                op.innerHTML = arr[i].classification_name
                op.value = i + 1
                // 新增/Add节点
                tourism_classification.appendChild(op)
                if (form_data2.tourism_classification == arr[i].tourism_classification) {
                    op.selected = true
                }
                $show_guide_name_driver_name()
                layui.form.render("select");
            }
        }

        async function guide_name() {
            var guide_name = document.querySelector("#guide_name")
            var op1 = document.createElement("option");
            op1.value = '0'
            guide_name.appendChild(op1)
            // 收集数据 长度
            var count
            // 收集数据 数组
            var arr = []
            let {data: res} = await axios.get(BaseUrl + '/api/tour_guide/get_list')
            count = res.result.count
            arr = res.result.list
            for (var i = 0; i < arr.length; i++) {
                var op = document.createElement("option");

                // 给节点赋值
                op.innerHTML = arr[i].guide_name
                op.value = i + 1
                // 新增/Add节点
                guide_name.appendChild(op)
                if (form_data2.guide_name == arr[i].guide_name) {
                    op.selected = true
                }
                layui.form.render("select");
            }
        }

        async function driver_name() {
            var driver_name = document.querySelector("#driver_name")
            var op1 = document.createElement("option");
            op1.value = '0'
            driver_name.appendChild(op1)
            // 收集数据 长度
            var count
            // 收集数据 数组
            var arr = []
            let {data: res} = await axios.get(BaseUrl + '/api/bus_driver/get_list')
            count = res.result.count
            arr = res.result.list
            for (var i = 0; i < arr.length; i++) {
                var op = document.createElement("option");

                // 给节点赋值
                op.innerHTML = arr[i].driver_name
                op.value = i + 1
                // 新增/Add节点
                driver_name.appendChild(op)
                if (form_data2.driver_name == arr[i].driver_name) {
                    op.selected = true
                }
                layui.form.render("select");
            }
        }

        layui.form.on('select(tourism_classification)', function (data) {
            form_data2.tourism_classification = data.elem[data.elem.selectedIndex].text;
            $show_guide_name_driver_name()
        })
        layui.form.on('select(guide_name)', function (data) {
            form_data2.guide_name = data.elem[data.elem.selectedIndex].text;
        })
        layui.form.on('select(driver_name)', function (data) {
            form_data2.driver_name = data.elem[data.elem.selectedIndex].text;
        })
        tourism_classification()
        guide_name()
        driver_name()


        //文本
        let route_name = document.querySelector("#route_name")
        route_name.onkeyup = function (event) {
            form_data2.route_name = event.target.value
        }
        //文本
        //文本
        let route_number = document.querySelector("#route_number")
        route_number.onkeyup = function (event) {
            form_data2.route_number = event.target.value
        }
        //文本
        //文本
        let starting_point_of_the_route = document.querySelector("#starting_point_of_the_route")
        starting_point_of_the_route.onkeyup = function (event) {
            form_data2.starting_point_of_the_route = event.target.value
        }
        //文本
        //文本
        let route_endpoint = document.querySelector("#route_endpoint")
        route_endpoint.onkeyup = function (event) {
            form_data2.route_endpoint = event.target.value
        }
        //文本
        //文本
        let team_opening_time = document.querySelector("#team_opening_time")
        team_opening_time.onkeyup = function (event) {
            form_data2.team_opening_time = event.target.value
        }
        //文本
        //数字
        let number_of_group_members = document.querySelector("#number_of_group_members")
        number_of_group_members.onkeyup = function (event) {
            form_data2.number_of_group_members = Number(event.target.value)
        }
        //数字
        //数字
        let individual_expenses = document.querySelector("#individual_expenses")
        individual_expenses.onkeyup = function (event) {
            form_data2.individual_expenses = Number(event.target.value)
        }
        //数字
        //多文本
        let tour_guide_information = document.querySelector("#tour_guide_information")
        //多文本
        route_number.value = form_data2.route_number
        // $("#route_number").attr("disabled", "disabled");
        var data = sessionStorage.data || ''
        if (data !== '') {
            var data2 = JSON.parse(data)
            Object.keys(form_data2).forEach(key => {
                Object.keys(data2).forEach(dbKey => {
                    if (key === dbKey) {
                        if (key !== 'examine_state' && key !== 'examine_reply') {
                            $('#' + key).val(data2[key])
                            form_data2[key] = data2[key]
                            $('#' + key).attr('disabled', 'disabled')


                            for (let key in form_data2) {
                                if (key == 'tourism_classification') {
                                    let alls = document.querySelector('#tourism_classification').querySelectorAll('option')
                                    let test = form_data2[key]
                                    for (let i = 0; i < alls.length; i++) {
                                        if (alls[i].innerHTML == test) {
                                            alls[i].selected = true
                                            form_data2.tourism_classification = alls[i].text
                                            console.log(222)
                                            layui.form.render("select");
                                        }
                                    }
                                }
                            }
                        }
                    }
                })
            })
            sessionStorage.removeItem("data");
        }


        if (tourist_routes_id !== '') {
            async function axios_get_3() {
                const {data: rese} = await axios.get(BaseUrl + '/api/tourist_routes/get_obj', {
                    params: {
                        tourist_routes_id: tourist_routes_id
                    }, headers: {
                        'x-auth-token': token
                    }
                })

                let data = rese.result.obj
                Object.keys(form_data2).forEach((key) => {
                    form_data2[key] = data[key];
                    $("#" + key).val(form_data2[key])
                });


                for (let key in data) {
                    if (key == 'tourism_classification') {
                        let alls = document.querySelector('#tourism_classification').querySelectorAll('option')
                        let test = data[key]
                        for (let i = 0; i < alls.length; i++) {
                            if (alls[i].innerHTML == test) {
                                alls[i].selected = true
                                form_data2.tourism_classification = alls[i].text
                                console.log(222)
                                layui.form.render("select");

                            }
                        }
                        $show_guide_name_driver_name()
                    }
                }
                for (let key in data) {
                    if (key == 'guide_name') {
                        let alls = document.querySelector('#guide_name').querySelectorAll('option')
                        let test = data[key]
                        for (let i = 0; i < alls.length; i++) {
                            if (alls[i].innerHTML == test) {
                                alls[i].selected = true
                                form_data2.guide_name = alls[i].text
                                console.log(333)
                                layui.form.render("select");
                            }
                        }
                    }
                }
                for (let key in data) {
                    if (key == 'driver_name') {
                        let alls = document.querySelector('#driver_name').querySelectorAll('option')
                        let test = data[key]
                        for (let i = 0; i < alls.length; i++) {
                            if (alls[i].innerHTML == test) {
                                alls[i].selected = true
                                form_data2.driver_name = alls[i].text
                                console.log(444)
                                layui.form.render("select");
                            }
                        }
                    }
                }


                if (user_group === '管理员') {
                    $("#route_name_box").show()
                } else {
                    if ($check_field('set', 'route_name') || $check_field('get', 'route_name')) {
                        $("#route_name_box").show()
                    } else {
                        $("#route_name_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#route_number_box").show()
                } else {
                    if ($check_field('set', 'route_number') || $check_field('get', 'route_number')) {
                        $("#route_number_box").show()
                    } else {
                        $("#route_number_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#cover_photo_box").show()
                } else {
                    if ($check_field('set', 'cover_photo') || $check_field('get', 'cover_photo')) {
                        $("#cover_photo_box").show()
                    } else {
                        $("#cover_photo_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#starting_point_of_the_route_box").show()
                } else {
                    if ($check_field('set', 'starting_point_of_the_route') || $check_field('get', 'starting_point_of_the_route')) {
                        $("#starting_point_of_the_route_box").show()
                    } else {
                        $("#starting_point_of_the_route_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#route_endpoint_box").show()
                } else {
                    if ($check_field('set', 'route_endpoint') || $check_field('get', 'route_endpoint')) {
                        $("#route_endpoint_box").show()
                    } else {
                        $("#route_endpoint_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#team_opening_time_box").show()
                } else {
                    if ($check_field('set', 'team_opening_time') || $check_field('get', 'team_opening_time')) {
                        $("#team_opening_time_box").show()
                    } else {
                        $("#team_opening_time_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#number_of_group_members_box").show()
                } else {
                    if ($check_field('set', 'number_of_group_members') || $check_field('get', 'number_of_group_members')) {
                        $("#number_of_group_members_box").show()
                    } else {
                        $("#number_of_group_members_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#individual_expenses_box").show()
                } else {
                    if ($check_field('set', 'individual_expenses') || $check_field('get', 'individual_expenses')) {
                        $("#individual_expenses_box").show()
                    } else {
                        $("#individual_expenses_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#tourism_classification_box").show()
                } else {
                    if ($check_field('set', 'tourism_classification') || $check_field('get', 'tourism_classification')) {
                        $("#tourism_classification_box").show()
                    } else {
                        $("#tourism_classification_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#tour_guide_information_box").show()
                } else {
                    if ($check_field('set', 'tour_guide_information') || $check_field('get', 'tour_guide_information')) {
                        $("#tour_guide_information_box").show()
                    } else {
                        $("#tour_guide_information_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#guide_name_box").show()
                } else {
                    if ($check_field('set', 'guide_name') || $check_field('get', 'guide_name')) {
                        $("#guide_name_box").show()
                    } else {
                        $("#guide_name_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#driver_name_box").show()
                } else {
                    if ($check_field('set', 'driver_name') || $check_field('get', 'driver_name')) {
                        $("#driver_name_box").show()
                    } else {
                        $("#driver_name_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#route_details_box").show()
                } else {
                    if ($check_field('set', 'route_details') || $check_field('get', 'route_details')) {
                        $("#route_details_box").show()
                    } else {
                        $("#route_details_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#booking_notice_box").show()
                } else {
                    if ($check_field('set', 'booking_notice') || $check_field('get', 'booking_notice')) {
                        $("#booking_notice_box").show()
                    } else {
                        $("#booking_notice_box").hide()
                    }
                }

                // Array.prototype.slice.call(document.getElementsByTagName('input')).map(i => i.disabled = true)
                // Array.prototype.slice.call(document.getElementsByTagName('select')).map(i => i.disabled = true)
                // Array.prototype.slice.call(document.getElementsByTagName('textarea')).map(i => i.disabled = true)
                //文本
                route_name.value = form_data2.route_name
                //文本


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'route_name')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'route_name'))) {
                } else {
                    $("#route_name").attr("disabled", true);
                    $("#route_name > input[name='file']").attr('disabled', true);
                }
                //文本
                route_number.value = form_data2.route_number
                //文本


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'route_number')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'route_number'))) {
                } else {
                    $("#route_number").attr("disabled", true);
                    $("#route_number > input[name='file']").attr('disabled', true);
                }


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'cover_photo')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'cover_photo'))) {
                } else {
                    $("#cover_photo").attr("disabled", true);
                    $("#cover_photo > input[name='file']").attr('disabled', true);
                }
                //文本
                starting_point_of_the_route.value = form_data2.starting_point_of_the_route
                //文本


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'starting_point_of_the_route')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'starting_point_of_the_route'))) {
                } else {
                    $("#starting_point_of_the_route").attr("disabled", true);
                    $("#starting_point_of_the_route > input[name='file']").attr('disabled', true);
                }
                //文本
                route_endpoint.value = form_data2.route_endpoint
                //文本


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'route_endpoint')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'route_endpoint'))) {
                } else {
                    $("#route_endpoint").attr("disabled", true);
                    $("#route_endpoint > input[name='file']").attr('disabled', true);
                }
                //文本
                team_opening_time.value = form_data2.team_opening_time
                //文本


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'team_opening_time')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'team_opening_time'))) {
                } else {
                    $("#team_opening_time").attr("disabled", true);
                    $("#team_opening_time > input[name='file']").attr('disabled', true);
                }
                //数字
                number_of_group_members.value = form_data2.number_of_group_members
                //数字


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'number_of_group_members')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'number_of_group_members'))) {
                } else {
                    $("#number_of_group_members").attr("disabled", true);
                    $("#number_of_group_members > input[name='file']").attr('disabled', true);
                }
                //数字
                individual_expenses.value = form_data2.individual_expenses
                //数字


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'individual_expenses')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'individual_expenses'))) {
                } else {
                    $("#individual_expenses").attr("disabled", true);
                    $("#individual_expenses > input[name='file']").attr('disabled', true);
                }


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'tourism_classification')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'tourism_classification'))) {
                } else {
                    $("#tourism_classification").attr("disabled", true);
                    $("#tourism_classification > input[name='file']").attr('disabled', true);
                }
                tour_guide_information.value = form_data2.tour_guide_information

                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'tour_guide_information')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'tour_guide_information'))) {
                } else {
                    $("#tour_guide_information").attr("disabled", true);
                    $("#tour_guide_information > input[name='file']").attr('disabled', true);
                }

                guide_name.value = form_data2.guide_name
                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'guide_name')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'guide_name'))) {
                } else {
                    $("#guide_name").attr("disabled", true);
                    $("#guide_name > input[name='file']").attr('disabled', true);
                }

                driver_name.value = form_data2.driver_name
                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'driver_name')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'driver_name'))) {
                } else {
                    $("#driver_name").attr("disabled", true);
                    $("#tour_guide_information > input[name='file']").attr('disabled', true);
                }


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'route_details')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'route_details'))) {
                } else {
                    $("#route_details").attr("disabled", true);
                    $("#route_details > input[name='file']").attr('disabled', true);
                }


                if (user_group === '管理员' || (form_data2['tourist_routes_id'] && $check_field('set', 'booking_notice')) || (!form_data2['tourist_routes_id'] && $check_field('add', 'booking_notice'))) {
                } else {
                    $("#booking_notice").attr("disabled", true);
                    $("#booking_notice > input[name='file']").attr('disabled', true);
                }
                let cover_photo_img = document.querySelector("#cover_photo_img")
                cover_photo_img.src = fullUrl(BaseUrl, form_data2.cover_photo)
                team_opening_time.value = layui.util.toDateString(form_data2.team_opening_time, "yyyy-MM-dd HH:mm:ss")
                layedit.setContent(route_details, form_data2.route_details)
                layedit.setContent(booking_notice, form_data2.booking_notice)
                layui.form.render("select");
            }

            axios_get_3()
        }


        submit.onclick = async function () {
            try {
                //文本
                form_data2.route_name = route_name.value
                //文本
                //文本
                form_data2.route_number = route_number.value
                //文本
                //文本
                form_data2.starting_point_of_the_route = starting_point_of_the_route.value
                //文本
                //文本
                form_data2.route_endpoint = route_endpoint.value
                //文本
                //文本
                form_data2.team_opening_time = team_opening_time.value
                //文本
                //数字
                form_data2.number_of_group_members = Number(number_of_group_members.value)
                //数字
                //数字
                form_data2.individual_expenses = Number(individual_expenses.value)
                //数字
                //多文本
                form_data2.tour_guide_information = tour_guide_information.value
                //多文本
                form_data2.route_details = layedit.getContent(route_details)
                form_data2.booking_notice = layedit.getContent(booking_notice)
                if (form_data2.tourism_classification !== '周边游') {
                    form_data2.guide_name = ''
                    form_data2.driver_name = ''
                }
            } catch (err) {
                console.log(err)
            }


            let customize_field = []
            customize_field.push({"field_name": "路线名称", "field_value": form_data2.route_name});
            customize_field.push({"field_name": "路线编号", "field_value": form_data2.route_number});
            customize_field.push({
                "field_name": "封面图片",
                "field_value": form_data2.cover_photo,
                "type": "image"
            });
            customize_field.push({"field_name": "路线起点", "field_value": form_data2.starting_point_of_the_route});
            customize_field.push({"field_name": "路线终点", "field_value": form_data2.route_endpoint});
            customize_field.push({
                "field_name": "开团时间",
                "field_value": form_data2.team_opening_time,
                "type": "datetime"
            });
            customize_field.push({"field_name": "组团人数", "field_value": form_data2.number_of_group_members});
            customize_field.push({"field_name": "单人费用", "field_value": form_data2.individual_expenses});
            customize_field.push({"field_name": "旅游分类", "field_value": form_data2.tourism_classification});
            customize_field.push({"field_name": "导游", "field_value": form_data2.guide_name});
            customize_field.push({"field_name": "司机", "field_value": form_data2.driver_name});
            customize_field.push({"field_name": "导游信息", "field_value": form_data2.tour_guide_information});
            customize_field.push({"field_name": "路线详情", "field_value": form_data2.route_details});
            customize_field.push({"field_name": "预订须知", "field_value": form_data2.booking_notice});


            if (tourist_routes_id == '') {
                console.log("新增/Add")
                const {data: res} = await axios.post(BaseUrl + '/api/tourist_routes/add?',
                    form_data2, {
                        headers: {
                            'x-auth-token': token,
                            'Content-Type': 'application/json'
                        }
                    })
                if (res.result == 1) {
                    layer.msg('确认完毕');
                    setTimeout(function () {
                        colseLayer()
                    }, 1000)
                } else {
                    layer.msg(res.error.message);
                }
            } else {
                console.log("详情/Details")

                const {data: res} = await axios.post(BaseUrl + '/api/tourist_routes/set?tourist_routes_id=' + tourist_routes_id,
                    form_data2, {
                        headers: {
                            'x-auth-token': token,
                            'Content-Type': 'application/json'
                        }
                    })
                if (res.result == 1) {
                    layer.msg('确认完毕');
                    setTimeout(function () {
                        colseLayer()
                    }, 1000)
                } else {
                    layer.msg(res.error.message);
                }
            }
        }

    })
    ;
</script>
<style>
    .layui-unselect.layui-form-select {
        width: auto;
    }
</style>
</html>
